class Solution(object):
    def nodesBetweenCriticalPoints(self, head):
        last_st = 0
        first_st = 0
        prev = head
        node = head.next
        min_val = float('inf')
        max_val = - float('inf')
        index = 1
        while node.next:
            if node.val > prev.val and node.val > node.next.val or (node.val < prev.val and node.val < node.next.val):
                if last_st:
                    min_val = min(min_val, index - last_st)
                    max_val = max(max_val, index - first_st)
                else:
                    first_st = index
                last_st = index
            index += 1
            node = node.next
        if min_val == float('inf'):
            return [-1, -1]
        else:
            return [min_val, max_val]
